package com.lagou.controller;

import com.lagou.pojo.Article;
import com.lagou.repository.ArticleRepository;
import com.lagou.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Controller
public class IndexController {

    @Autowired
    ArticleService articleService;

    @RequestMapping("/")
    public String toIndex(){
        return "redirect:/index";
    }

    @RequestMapping("/index")
    public String index(Model model,
                          @RequestParam(value = "pageNum", defaultValue = "0") Integer pageNum,
                          @RequestParam(value = "pageSize", defaultValue = "3") Integer pageSize
    ){
        Page<Article> artPage = articleService.queryPage(pageNum, pageSize);
        model.addAttribute("artPage", artPage);
        return "client/index";
    }

}
